/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package networkrespnse;


import core.ParameterDecoder;
import utils.Utils;
/**
 *
 * @author Kvest
 */
public class RelayCommunicationResponse extends Response
{
    private String relayCommunicationType;
    private String relayAnswerType;
    private int relayID;
    private long openRelayDate;
    private int fromDriver;
    
    public RelayCommunicationResponse(byte[] data)
    {
        super(RELAY_COMMUNICATION_RESPONSE);
        relayCommunicationType = "";
        relayAnswerType = "";
        relayID = -1;
        openRelayDate = 0;
        fromDriver = -1;

        parse(data);
    }

    protected void parse(byte[] data)
    {
        byte[] body,temp;
        int index,size;

        //��������  body
        body = ParameterDecoder.getTransferBody(data);
        temp = new byte[4];
        index = 0;
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        index += Utils.byteToInt(temp);

        //�������� RelayCommunicationType
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        size = Utils.byteToInt(temp);
        temp = new byte[size];
        for (int i=0;i<size;i++)
        {
                temp[i] = body[index++];
        }
        relayCommunicationType = Utils.byteToString(temp);

        //�������� RelayAnswerType
        temp = new byte[4];
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        size = Utils.byteToInt(temp);
        temp = new byte[size];
        for (int i=0;i<size;i++)
        {
                temp[i] = body[index++];
        }
        relayAnswerType = Utils.byteToString(temp);

        //�������� RelayID
        temp = new byte[4];
        for (int i=0;i<4;i++)
        {
                temp[i] = body[index++];
        }
        relayID = Utils.byteToInt(temp);

        //�������� OpenRelayDate
        temp = new byte[8];
        for (int i=0;i<8;i++)
        {
                temp[i] = body[index++];
        }
        openRelayDate = Utils.byteToDate(temp);

        //�������� FromDriver
        temp = new byte[4];
        temp[0] = body[index++];
        temp[1] = 0; temp[2] = 0; temp[3] = 0;
        fromDriver = Utils.byteToInt(temp);

        System.gc();
    }

    public String getRelayCommunicationType()
    {
        return relayCommunicationType;
    }

    public String getRelayAnswerType()
    {
        return relayAnswerType;
    }

    public int getRelayID()
    {
        return relayID;
    }

    public long getOpenRelayDate()
    {
        return openRelayDate;
    }

    public int getFromDriver()
    {
        return fromDriver;
    }
}
